package com.jiangjiang.eshop.logistics.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangjiang.eshop.logistics.dto.FreightTemplateDTO;
import com.jiangjiang.eshop.logistics.dto.FreightTemplateQueryDTO;
import com.jiangjiang.eshop.logistics.dto.LogisticTraceQueryDTO;
import com.jiangjiang.eshop.logistics.service.FreightTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author Jianghaowen
 * @Date 2021/9/14
 * @Description: TODO
 * @Version V1.0
 **/
@Slf4j
@RestController
@RequestMapping("/logistics/freightTemplate")
public class FreightTemplateController {
    @Autowired
    private FreightTemplateService freightTemplateService;
    /**
     * 运费模板分页查询
     * @param dto 查询入参
     * @return 查询结果
     */
    @PostMapping("/queryForPage")
    public Page<FreightTemplateDTO> queryForPage(@RequestBody FreightTemplateQueryDTO dto){
        try {
            return freightTemplateService.queryForPage(dto);
        }catch (Exception e){
            log.warn("LogisticsController queryForPage error",e);
        }
        return null;
    }
    /**
     * 根据运费模板id查询记录
     * @param id 运费模板id
     * @return 查询结果
     */
    @GetMapping("/queryById/{id}")
    public FreightTemplateDTO queryById(@PathVariable("id") Long id){
        try {
            return freightTemplateService.queryById(id);
        }catch (Exception e){
            log.warn("LogisticsController queryById error",e);
        }
        return null;
    }

    /**
     * 根据运费模板id查询记录
     * @param dto 运费模板数据
     * @return 处理结果
     */
    @PostMapping("/createTemplate")
    public Boolean createTemplate(@RequestBody FreightTemplateDTO dto){
        try {
            return freightTemplateService.createTemplate(dto);
        }catch (Exception e){
            log.warn("LogisticsController createTemplate error",e);
        }
        return false;
    }

    /**
     * 运费模板更新
     * @param dto 运费模板数据
     * @return 处理结果
     */
    @PostMapping("/updateTemplate")
    public Boolean updateTemplate(FreightTemplateDTO dto){
        try {
            return freightTemplateService.updateTemplate(dto);
        }catch (Exception e){
            log.warn("LogisticsController updateTemplate error",e);
        }
        return false;
    }

}
